package com.itheima.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @version 1.0
 * @description WebMvcConfigurer: MVC的配置类, controller相关。springMVC核心配置类
 * @package com.itheima.interceptor
 */
@Configuration // 配置类，注册bean对象，衍生自@Component
public class WebConfig implements WebMvcConfigurer {

    //alt+insert inst, ctrl+o
    //鼠标右击->generate生成

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
            // 拦截指定路径的请求 /**所有请求
            .addPathPatterns("/**")
            // 排除的请求的路径, 不再进入拦截器
            .excludePathPatterns("/login");
    }
}
